<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class part_controller extends wxapp_controller{
	function list_action(){
        $time=time();
		$where = "(`deadline`>'".$time."' OR `deadline`=0) AND `state`=1 AND `r_status`<>2";
		$page=intval($_POST['page']);
		$cycle=$_POST['cycle'];
		$provinceid=$_POST['provinceid'];
		$cityid=$_POST['cityid'];
		$three_cityid=$_POST['three_cityid'];
		$uid=$_POST['uid'];
		$type=$_POST['type'];
		$order=$_POST['order'];
		$limit=$_POST['limit'];
		$keyword=$this->stringfilter($_POST['keyword']);
		$limit=!$limit?10:$limit; 
		if($uid){
			$where.=" AND `uid`='".$uid."'";
		}
		if($provinceid){//类别ID
			$where.=" AND `provinceid`='".$provinceid."'";
		}
		if($cityid){//类别ID
			$where.=" AND `cityid`='".$cityid."'";
		}
		if($three_cityid){//类别ID
			$where.=" AND `three_cityid`='".$three_cityid."'";
		} 
		if($cycle){//关键字
			$where.=" AND `billing_cycle`='".$cycle."'";
		} 
		if($type){//关键字
			$where.=" AND `type`='".$type."'";
		} 
		if($keyword){//关键字
			$where.=" AND `name` like '%".$keyword."%'";
		} 
		if($order){//排序
			$where.=" order by ".$order;
		}else{
			$where.=" order by `lastupdate` desc";
		}
		if($page){//分页
			$pagenav=($page-1)*$limit;
			$where.=" limit $pagenav,$limit";
		}else{
			$where.=" limit $limit";
		}
		$rows=$this->obj->DB_select_all("partjob",$where);
		if($rows && is_array($rows)){			
			include(PLUS_PATH."city.cache.php");
			include(PLUS_PATH."part.cache.php");
			$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));//今天开始时间戳
			$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));//昨天开始时间戳
			$week=strtotime(date("Y-m-d",strtotime("-1 week")));//一周内时间戳
			
			$list=$jobids=$comuids=array();
			foreach($rows as $v){
				$jobids[]=$v['id'];
				$comuids[]=$v['uid'];
			}
			$applys=$this->obj->DB_select_all("part_apply","`jobid` in(".pylode(',',$jobids).") group by `jobid` desc","count(id) as num,jobid");
			$com=$this->obj->DB_select_all("company","`uid` in(".pylode(',',$comuids).")","`uid`,`shortname`");
			foreach($rows as $key=>$va){ 										   			
				$list[$key]['applynum']=0;
				foreach($applys as $val){
					if($val['jobid']==$va['id']){
						$list[$key]['applynum']=$val['num'];
					}
				} 										
				$list[$key]['id']		 =$va['id']; 
				$list[$key]['salary']    =$va['salary'];
				$list[$key]['salary_type']=$va['salary_type'];
				$list[$key]['billing_cycle']=$va['billing_cycle'];
				$list[$key]['type']		 =$va['type'];
				$list[$key]['deadline']	 =$va['deadline'];				
				$list[$key]['hits']	 =$va['hits'];
				$list[$key]['edate']=$va['edate'];								
				$list[$key]['lastupdate']=$va['lastupdate'];
				$list[$key]['provinceid']=$va['provinceid']; 
				$list[$key]['cityid']	 =$va['cityid']; 
				$list[$key]['three_cityid']=$va['three_cityid']; 
				$list[$key]['name']		 =mb_substr($va['name'], 0,16,'utf-8');
				if($com){
					foreach($com as $val){
						if($val['uid']==$va['uid']&&$val['shortname']){
							$list[$key]['com_name']	 =mb_substr($val['shortname'], 0,14,'utf-8');
						}else{
							$list[$key]['com_name']	 =mb_substr($va['com_name'], 0,14,'utf-8');
						}
					}
				}else{
					$list[$key]['com_name']		=$va['com_name'];
				}
				
				$list[$key]['x']		 =$va['x']; 
				$list[$key]['y']		 =$va['y'];  
				//小程序所需汉字字段-start
				$list[$key]['city']      =$city_name[$va['cityid']]?$city_name[$va['provinceid']].'-'.$city_name[$va['cityid']]:$city_name[$va['provinceid']];
				$list[$key]['billing_cycle_n']=$partclass_name[$va['billing_cycle']];
				$list[$key]['salary_type_n']=$partclass_name[$va['salary_type']];
				if ($va['lastupdate']>$week && $va['lastupdate']<$beginYesterday){
				    $list[$key]['lastupdate_n']="一周内";
				}elseif($va['lastupdate']>$beginYesterday && $va['lastupdate']<$beginToday){
				    $list[$key]['lastupdate_n']="昨天";
				}elseif($va['lastupdate']>$beginToday){
				    $list[$key]['lastupdate_n']=date("H:i",$va['lastupdate']);
				}else{
				    $list[$key]['lastupdate_n']=date("Y-m-d",$va['lastupdate']);
				}
				//小程序所需汉字字段-end
			}   
			$data['list']=$list;
			$data['error']=1;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die;
	}
	function getclass_action(){
		$rows=$this->obj->DB_select_all("partclass","1 order by `sort` asc");
		if($rows&&is_array($rows)){
			$parent=array();
			foreach($rows as $val){
				if($val['keyid']=='0'){
					$parent[$val['id']]=array('id'=>$val['id'],'name'=>$val['name'],'variable'=>$val['variable']);	
				} 
			}
			foreach($rows as $val){
				foreach($parent as $key=>$v){
					if($val['keyid']==$v['id']){
						$parent[$key]['son'][]=array('id'=>$val['id'],'name'=>$val['name']);
					}
				}
			}
		}
		echo json_encode($parent);die;
	}
	function show_action(){//职位内容页
		$id=(int)$_POST['id'];
		$usertype=(int)$_POST['usertype'];
		$uid=(int)$_POST['uid'];
		$sy_part_web=(int)$this->config['sy_part_web'];
		if($sy_part_web=='2'){
			$data['error']=4;
			echo json_encode($data);die;
		}
		if(!$id){
			$data['error']=3;
			echo json_encode($data);die;
		}
		$row=$this->obj->DB_select_once("partjob","`id`='".$id."'");
		if($uid!=$row['uid']){
			if($row['state']!='1'||($row['deadline']!=0 && $row['deadline']<time())){
				unset($row);
			}
		} 
		if(is_array($row)&&$row){ 
		    include PLUS_PATH."/city.cache.php";
		    include(PLUS_PATH."part.cache.php");
		    include(CONFIG_PATH."db.data.php");
		    $morning=array("0101","0201","0301","0401","0501","0601","0701");
		    $noon=array("0102","0202","0302","0402","0502","0602","0702");
		    $afternoon=array("0103","0203","0303","0403","0503","0603","0703");
			$this->obj->DB_update_all("partjob","`hits`=`hits`+1","`id`='".$id."'");
			$list=array();
			$list['apply']=0;
			$list['collect']=0;
			if($usertype=="1"){
				$apply=$this->obj->DB_select_once("part_apply","`uid`='".$uid."' AND `jobid`='".$id."'");
				if($apply['id']){
					$list['apply']=1;
				}
				$collect=$this->obj->DB_select_once("part_collect","`uid`='".$uid."' AND `jobid`='".$id."'");
				if($collect['id']){
					$list['collect']=1;
				}
			}
			$list['id']		=$row['id'];
			$list['comid']	=$row['uid'];
			$list['cityid']	=$row['cityid'];
			$list['hits']	=$row['hits'];
			$list['lastupdate']	=$row['lastupdate'];
			$list['salary']	=$row['salary'];
			$list['salary_type']	=$row['salary_type'];
			$list['type']	=$row['type'];
			$list['number']	=$row['number'];
			$list['sex']	=$row['sex'];
			$list['sdate']	=$row['sdate'];
			$list['edate']	=$row['edate'];
			$list['deadline']	=$row['deadline'];
			$coordinates=$this->Convert_BD09_To_GCJ02($row['x'],$row['y']);
			$list['x']=$coordinates['lng'];
			$list['y']=$coordinates['lat'];
			$list['name']	=$row['name'];
			$com=$this->obj->DB_select_once("company","`uid`='".$uid."'","`uid`,`shortname`");
			if($com['shortname']){
				$list['com_name']	=$com['shortname'];
			}else{
				$list['com_name']	=$row['com_name'];
			}
			
			$list['worktime']	=$row['worktime'];
			$list['billing_cycle']	=$row['billing_cycle'];
			$list['address']	=$row['address'];
			$list['content']	=$row['content'];
			$list['linkman']	=$row['linkman'];
			$list['linktel']	=$row['linktel']; 
			$list['provinceid']	=$row['provinceid']; 
			$list['cityid']	=$row['cityid']; 
			$list['three_cityid']	=$row['three_cityid']; 
			//小程序所需汉字字段-start
			$list['city']  =$city_name[$row['cityid']]?$city_name[$row['provinceid']].'-'.$city_name[$row['cityid']]:$city_name[$row['provinceid']];
			$list['lastupdate_n'] = date("Y-m-d",$row['lastupdate']);
			if ($row['deadline']>0){
			    $list['deadline_n'] = date("Y-m-d",$row['deadline']);
			}else{
			    $list['deadline_n'] = '长期招聘'; 
			}
			$list['billing_cycle_n']=$partclass_name[$row['billing_cycle']];
			$list['salary_type_n']=$partclass_name[$row['salary_type']];
			$list['type_n']	      =$partclass_name[$row['type']];
			$list['sex_n']        =$arr_data['sex'][$row['sex']];
			$list['worktime_n']   =$row['worktime'];
			$list['sex_n']        =$arr_data['sex'][$row['sex']];
			$list['content']	  =strip_tags($row['content']);
			$worktime=@explode(',', $row['worktime']);
			foreach ($morning as $v){
			    if (in_array($v, $worktime)){
			        $list['morning'][]=1;
			    }else{
			        $list['morning'][]=0;
			    }
			}
			foreach ($noon as $v){
			    if (in_array($v, $worktime)){
			        $list['noon'][]=1;
			    }else{
			        $list['noon'][]=0;
			    }
			}
			foreach ($afternoon as $v){
			    if (in_array($v, $worktime)){
			        $list['afternoon'][]=1;
			    }else{
			        $list['afternoon'][]=0;
			    }
			}
			//小程序所需汉字字段-end
			foreach($list as $k=>$v){
				if(is_array($v)){
					foreach($v as $key=>$val){
						$list[$k][$key]=isset($val)?$val:'';
					}
				}else{
					$list[$k]=isset($v)?$v:'';
				}
			}
			$data['list']=count($list)?$list:array();
			$data['error']=1;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die;
	}

	function apply_action(){
		//$_POST = $this->CheckAppUser(); 
		$usertype=(int)$_POST['usertype'];
		$jobid=(int)$_POST['jobid'];
		$uid=(int)$_POST['uid'];
		$user=$this->obj->DB_select_once("member","`uid`='".$uid."'",'usertype');
		if($user['usertype']!="1"){
			$data['error']=6;//您不是个人用户
			$data['errmsg']='您不是个人用户';
			echo json_encode($data);die;
		}
		if($this->config['com_resume_partapply']==1){
		    $Resume=$this->MODEL("resume");
		    $arr=$Resume->SelectExpectOne(array("uid"=>$uid));
		    if(empty($arr)){
		        $data['error']=3;//拥有简历才可以报名
		        $data['errmsg']='拥有简历才可以报名';
				echo json_encode($data);die;
		    }
		}	
		$jobinfo=$this->obj->DB_select_once("partjob","`id`='".$jobid."'","deadline,uid,name");
		if($jobinfo['deadline']<time()&&$jobinfo['deadline']>1){
			$data['error']=4;//报名截止
			$data['errmsg']='报名截止';
			echo json_encode($data);die;
		}
		$row=$this->obj->DB_select_once("part_apply","`jobid`='".$jobid."' AND `uid`='".$uid."'","id");
		if($row['id']){
			$data['error']=5;//已报名
			$data['errmsg']='已报名';
			echo json_encode($data);die;
		}
		$appdata=array(
			'uid'=>$uid,
			'jobid'=>$jobid,
			'comid'=>$jobinfo['uid'],
			'ctime'=>time()
		);
		$nid=$this->obj->insert_into("part_apply",$appdata);
		if($nid){
			$info=$this->obj->DB_select_once("member","`uid`='".$uid."'");
			$fdata=$this->forsend(array("uid"=>$uid,"usertype"=>1));
			$sdata['type']="apply";
			$sdata['name']=$fdata['name'];
			$sdata['uid']=$info['uid'];
			$sdata['username']=$info['username'];
			$sdata['email']=$info['email'];
			$sdata['moblie']=$info['moblie'];
			$sdata['jobname']=$jobinfo['name'];
            $notice = $this->MODEL('notice');
            $notice->sendEmailType($sdata);
			$notice->sendSMSType($sdata);
			$this->member_log("申请职位 ".$jobinfo['name'], $uid, 1,6,1);
			//推送
			$push = $this->getPush();
			if ($push){
			    $resumeM = $this->MODEL('resume');
			    $resume = $resumeM->SelectResume(array('uid'=>$uid),'`name`');
			    
			    $content = mb_substr('兼职：'.$jobinfo['name'].'有新的申请', 0, 24, 'UTF-8');
			    $this->makePush($resume['name'], $content, array('uid'=>$jobinfo['uid']), $push);
			}
			$data['error']=1;//成功
		}else{
			$data['error']=2;
			$data['errmsg']='报名失败';
		}
		echo json_encode($data);die;
	}
	function fav_action(){
		$usertype=intval($_POST['usertype']);
		$uid=intval($_POST['uid']);
		if($usertype!=1){
			$data['error']=4;//您不是个人用户
			$data['errmsg']='您不是个人用户';
			echo json_encode($data);die;
		}else{
			/**验证权限**/
			//$_POST = $this->CheckAppUser();
			/**验证权限结束**/
			
			$row=$this->obj->DB_select_once("part_collect","`uid`='".$uid."' AND `jobid`='".(int)$_POST['jobid']."'");
			if(!empty($row)){
				$data['error']=5;//已收藏
				$data['errmsg']='已收藏';
				echo json_encode($data);die;
			}else{
				$value=array(
					'uid'=>$uid,
					'jobid'=>(int)$_POST['jobid'],
					'comid'=>(int)$_POST['comid'],
					'ctime'=>time()
				); 
				$nid=$this->obj->insert_into("part_collect",$value); 
				if($nid){
				    $this->member_log("收藏兼职 ".$value['job_name'], $uid, 1,5,1);
					$data['error']=1;//成功
				}else{
					$data['error']=2;
					$data['errmsg']='收藏失败';
				}
				echo json_encode($data);die;
			}
		} 
	}
	//wxapp个人会员兼职收藏列表
	function favlist_action(){//个人会员收藏兼职列表
		$uid=intval($_POST['uid']); 
		$where="`uid`='".$uid."'  order by `id` desc"; 
		$rows=$this->obj->DB_select_all("part_collect",$where);
		if($rows&&is_array($rows)){
			$res=$day=$jobids=array();
			foreach($rows as $k=>$val){
				$jobids[]=$val['jobid'];
				$day[$k]['id']=$val['id'];
				$day[$k]['ctime']=date("Y-m-d",$val['ctime']);
			}
			foreach ($day as $value) {
				if(isset($res[$value['ctime']])){
					unset($value['ctime']);
				}else{
					$res[$value['ctime']] = $value;
				}
			}
			$joblist=$this->obj->DB_select_all("partjob","`id` in(".pylode(',',$jobids).")","`id`,`name`,`cityid`,`com_name`,`salary`,`salary_type`,`provinceid`,`three_cityid`,`state`,`x`,`y`"); 
			include(PLUS_PATH."city.cache.php");
			include(PLUS_PATH."com.cache.php");
			include(PLUS_PATH."part.cache.php");
			foreach($rows as $key=>$val){
				foreach($res as $v){
					if($v['id']==$val['id']){
						$rows[$key]['ctime_n'] 	=$v['ctime'];	
					} 
				}
				foreach($joblist as $v){
					if($val['jobid']==$v['id']){
						$rows[$key]['x']=$v['x'];
						$rows[$key]['y']=$v['y'];
						$rows[$key]['state']=$v['state'];
						$rows[$key]['salary']=$v['salary'];
						$rows[$key]['salary_type']=$partclass_name[$v['salary_type']];
						$rows[$key]['job_name']=$v['name'];
						$rows[$key]['city']=$city_name[$v['cityid']];
						$rows[$key]['province']=$city_name[$v['provinceid']];
						$rows[$key]['three_city']=$city_name[$v['three_cityid']];
						$rows[$key]['com_name']=$v['com_name'];
					}
				}
			} 
			$data['list']=$rows;
			$data['error']=1;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die; 
	}
	//wxapp个人会员兼职收藏删除
	function delfavpart_action(){
		$usertype=intval($_POST['usertype']);
		$id=intval($_POST['ids']);
		$uid=intval($_POST['uid']);
		if($usertype!=1){
			$data['error']=2;//您不是个人用户
			$data['msg']="您不是个人用户";
			echo json_encode($data);die;
		}else{
			//$_POST = $this->CheckAppUser();
			$this->obj->DB_delete_all("part_collect","`uid`='".$uid."' AND `id`='".$id."'");
			$data['error']=1;//删除成功
			$data['msg']="删除成功";
			echo json_encode($data);die;
		}
	}
	//wxapp个人、企业会员兼职报名列表
	function applylist_action(){//个人、企业会员兼职报名管理
		$uid=intval($_POST['uid']); 
		$usertype=intval($_POST['usertype']); 
		if($usertype=='1'){
			$where="`uid`='".$uid."'  order by `id` desc"; 
		}else{
			$where="`comid`='".$uid."'  order by `id` desc"; 
		} 
		$rows=$this->obj->DB_select_all("part_apply",$where);
		if($rows&&is_array($rows)){ 
			include PLUS_PATH."/city.cache.php";
			include PLUS_PATH."/user.cache.php";
			include(CONFIG_PATH."db.data.php");
			$res=$day=$jobids=$uids=array();
			foreach($rows as $k=>$val){
				$jobids[]=$val['jobid'];
				$uids[]=$val['uid'];
				if($usertype==1){
					$day[$k]['id']=$val['id'];
					$day[$k]['ctime']=date("Y-m-d",$val['ctime']);
				}
			}
			if($usertype==1){
				foreach ($day as $value) {
					if(isset($res[$value['ctime']])){
						unset($value['ctime']);
					}else{
						$res[$value['ctime']] = $value;
					}
				}
			}
			$joblist=$this->obj->DB_select_all("partjob","`id` in(".pylode(',',$jobids).")","`id`,`name`,`cityid`,`com_name`,`x`,`y`");
			$resume=$this->obj->DB_select_all("resume","`uid` in(".pylode(',',$uids).")","`uid`,`name`,`sex`,`edu`,`birthday`,`telphone`,`def_job`");
			foreach($rows as $key=>$val){
				if($usertype==1){
					foreach($res as $v){
						if($v['id']==$val['id']){
							$rows[$key]['ctime_n'] 	=$v['ctime'];	
						} 
					}
				}else{
					$rows[$key]['ctime_n'] 	=date("Y-m-d",$val['ctime']);	
				}
				
				foreach($joblist as $v){
					if($val['jobid']==$v['id']){
						$rows[$key]['x']=$v['x'];
						$rows[$key]['y']=$v['y'];
						$rows[$key]['job_name']=$v['name'];
						$rows[$key]['city']=$city_name[$v['cityid']];
						$rows[$key]['com_name']=$v['com_name']; 
					}
				}
				foreach($resume as $v){
					if($val['uid']==$v['uid']){
						if($v['birthday']){
							$birthday=@explode('-',$v['birthday']);
							$rows[$key]['age']=date("Y")-$birthday[0];
						}
						$rows[$key]['eid']=$v['def_job'];
						$rows[$key]['telphone']=$v['telphone'];
						$rows[$key]['uname']=$v['name'];
						$rows[$key]['edu_n']=$userclass_name[$v['edu']];
						$rows[$key]['sex_n']=$arr_data['sex'][$v['sex']];
					}
				}
			} 
			$data['list']=$rows;
			$data['error']=1;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die; 
	}
	//wxapp个人会员兼职报名删除
	function delapply_action(){//删除兼职报名
		$usertype=intval($_POST['usertype']);
		$id=intval($_POST['ids']);
		$uid=intval($_POST['uid']);  
		if($usertype=='1'){
			$this->obj->DB_delete_all("part_apply","`uid`='".$uid."' AND `id`='".$id."'");
		}else{
			$this->obj->DB_delete_all("part_apply","`comid`='".$uid."' AND `id`='".$id."'");
		} 
		$data['error']=1;//删除成功
		$data['msg']="删除成功";
		echo json_encode($data);die; 
	}
	function delpart_action(){//企业删除兼职
		$usertype=intval($_POST['usertype']);
		$id=intval($_POST['id']);
		$uid=intval($_POST['uid']);
		if($id){
			$this->obj->DB_delete_all("partjob","`uid`='".$uid."' AND `id`='".$id."'"); 
			$data['error']=1;//删除成功
			$data['msg']="删除成功";
		}else{
			$data['error']=2;
			$data['msg']="删除失败";
		} 
		echo json_encode($data);die; 
	}
	function partlist_action(){
		$uid=(int)$_POST['uid'];
		if(!$uid){
			$data['error']=3;
			echo json_encode($data);die;
		} 
		$where="`uid`='".$uid."'  order by `id` desc"; 
		$rows=$this->obj->DB_select_all("partjob",$where);
		if(is_array($rows) && !empty($rows)){
			$jobids=array();
			foreach($rows as $v){
				$jobids[]=$v['id'];
			}
			$applys=$this->obj->DB_select_all("part_apply","`jobid` in(".pylode(',',$jobids).") group by `jobid` desc","count(id) as num,jobid");
			foreach($rows as $k=>$v){
				$data2[$k]['applynum']=0;
				foreach($applys as $val){
					if($val['jobid']==$v['id']){
						$data2[$k]['applynum']=$val['num'];
					}
				}

				$data2[$k]['id']=$v['id'];
				$data2[$k]['name']=$v['name'];
				$data2[$k]['lastupdate_n']=date("Y-m-d",$v['lastupdate']);
				$data2[$k]['hits']=$v['hits'];
				if($v['edate']>0){
					$data2[$k]['edate_n']=date("Y-m-d",$v['edate']);
					$data2[$k]['deadline_n']=date("Y-m-d",$v['deadline']);
				}else{
					$data2[$k]['edate_n']="长期招聘";
				}
				if($v['edate']!=0&&$v['edate']<time()){
					$data2[$k]['state']="已过期";
				}elseif($v['state']==1){
					$data2[$k]['state']="已审核";
				}elseif($v['state']==3){
					$data2[$k]['state']="未通过";
				}elseif($v['state']==0){
					$data2[$k]['state']="未审核";
				}
				
			}
			$data['list']=$data2;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die;
	}
	function partedit_action(){
		$id=intval($_POST['id']);
		$uid=intval($_POST['uid']);
		//$this->CheckAppUser(); 
		if($id){
			include(PLUS_PATH."part.cache.php");
			include(PLUS_PATH."city.cache.php");
			$row=$this->obj->DB_select_once("partjob","`uid`='".$uid."' AND `id`='".$id."'");
			$data['id']=$row['id'];
			$data['name']=$row['name'];
			$data['type']=$row['type'];
			$data['type_n']=$partclass_name[$row['type']];
			$data['number']=$row['number'];
			if($row['sdate']){
				$data['sdate']=date("Y-m-d",$row['sdate']);
			}
			if($row['edate']>0){
				$data['edate']=date("Y-m-d",$row['edate']);
			}else{
			    $data['edate']=0;
			}
			if($row['deadline']){
				$data['deadline']=date("Y-m-d",$row['deadline']);
			}
			$data['sex']=$row['sex'];
			$data['salary']=$row['salary'];
			$data['salarytype']=$row['salary_type'];
			$data['billing_cycle']=$row['billing_cycle'];
			$data['province']=$row['provinceid'];
			$data['city']=$row['cityid'];
			$data['threecity']=$row['three_cityid'];
			$data['address']=$row['address'];
			$data['content']=preg_replace(array("/\r\n\r\n\r\n/"), array("\r\n"),strip_tags($row['content']));
			$data['linkman']=$row['linkman'];
			$data['linktel']=$row['linktel'];
			$worktime=@explode(",",$row['worktime']);
			if($row['worktime']){
				foreach($worktime as $k=>$v){
					$work[$k]['name']=$v;
					$work[$k]['checked']=true;
				}
				$data['worktime']=$work;
			}
			$coordinates=$this->Convert_BD09_To_GCJ02($row['x'],$row['y']);
			$data['x']=$coordinates['lng'];
			$data['y']=$coordinates['lat'];
			$data['error']=1;
		}else{
			$data['error']=2;
		}
		echo json_encode($data);die; 
	}
	function partsave_action(){ 
	    $_POST=$this->post_trim($_POST);
		if(!$_POST['name']||!$_POST['type']||!$_POST['number']||!$_POST['address']||!$_POST['linkman']||!$_POST['linktel']){
			$arr['error']='3';
			$arr['msg']="请完善信息";
			echo json_encode($arr);die;
		} 
		$uid=intval($_POST['uid']);
		$id=intval($_POST['id']);
		if(!$id){
		    $statis=$this->company_satic($uid);
		    if ($statis['addpartnum']==0){
		        $data['error']=3;
		        $data['msg']='发布兼职套餐已用完';
		        echo json_encode($data);die;
		    }elseif ($statis['addpartnum']==3){
		        $data['error']=3;
		        $data['msg']="您的".$this->config['integral_pricename']."不足！";
		        echo json_encode($data);die;
		    }
		}
		$coordinates=$this->Convert_GCJ02_To_BD09($this->stringfilter($_POST['x']), $this->stringfilter($_POST['y']));
		if($_POST['timetype']){
		    $_POST['edate']="";
		    $_POST['deadline']="";
		}else{
		    $deadline=strtotime($_POST['deadline']);
		    $edate=strtotime($_POST['edate']);
		    if($deadline>$edate){
		        $arr['error']='3';
		        $arr['msg']="截止日期不能大于结束日期";
		        echo json_encode($arr);die;
		    }
		}
		$data=array(
			'name'=>$this->stringfilter($_POST['name']),
			'type'=>intval($_POST['type']),
			'sdate'=>strtotime($_POST['sdate']),
			'edate'=>strtotime($_POST['edate']),
			'deadline'=>strtotime($_POST['deadline']),
			'number'=>intval($_POST['number']),
			'sex'=>intval($_POST['sex']),
			'salary'=>intval($_POST['salary']),
			'salary_type'=>intval($_POST['salarytype']),
			'billing_cycle'=>intval($_POST['billing_cycle']),
			'provinceid'=>intval($_POST['province']),
			'cityid'=>intval($_POST['city']),
			'three_cityid'=>intval($_POST['threecity']),
			'worktime'=>$this->stringfilter($_POST['worktime']),
			'address'=>$this->stringfilter($_POST['address']),
			'x'=>$coordinates['lng'],
			'y'=>$coordinates['lat'],
			'content'=>$this->stringfilter($_POST['content']),
			'linkman'=>$this->stringfilter($_POST['linkman']),
			'linktel'=>$this->stringfilter($_POST['linktel']),
			'state'=>$this->config['com_partjob_status']
		);
		
		if($id){
			$info=$this->obj->DB_select_once("partjob","`uid`='".$uid."' AND `id`='".$id."'","`id`");
		} 
		$this->get_com(1,$uid);
		if($info['id']){
			$nid=$this->obj->update_once("partjob",$data,array("id"=>$info['id']));
		}else{
			$company=$this->obj->DB_select_once("company","`uid`='".$uid."'","`name`,`did`");
			$data['com_name']=$company['name'];
			$data['did']=$company['did'];
			$data['uid']=$uid;
			$data['addtime']=time();
			$data['lastupdate']=time();
			$nid=$this->obj->insert_into("partjob",$data);
		}
		if($nid){
		    
	        if($this->config['com_partjob_status']=="1"){
				$arr['error']='1';
				$arr['msg']="提交成功";
			}else{
				$arr['error']='1';
				$arr['msg']="提交成功，等待审核";
			}
		}else{
			$arr['error']='2';
			$arr['msg']="提交失败";
		}
		echo json_encode($arr);die;
	}
	//1添加职位，2修改职位,3刷新职位
	function get_com($type,$uid){
	    $statis=$this->obj->DB_select_once("company_statis","`uid`='".$uid."'");
	    if($statis['rating']){
	        $rating = $this->obj->DB_select_once('company_rating','`id`="'.$statis['rating'].'"','`type`');
	        if ($statis['vip_etime']>time() || $statis['vip_etime']==0){
	            if ($rating['type']==1){
	                if($type==1){
	                    if($statis['part_num']>0){
	                        $value="`part_num`=`part_num`-1";
	                    }else{
	                        if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){
	                            $this->intergal($statis,$uid);
	                        }else{
	                            $data['error']=2;//会员发布兼职用完.
	                            $data['msg']='会员发布兼职用完';
	                            echo json_encode($data);die;
	                        }
	                    }
	                }
	                if($value){
	                    $this->obj->DB_update_all("company_statis",$value,"uid='".$uid."'");
	                }
	            }
	        }else{
	            $data['error']=2;
	            $data['msg']='会员已过期';
	            echo json_encode($data);die;
	        }
	    }else{
	        $this->intergal($statis,$uid);
	    }
	}
	// 积分 扣除
	function intergal($statis,$uid){
	    if($this->config['integral_partjob']){
	        if($this->config['integral_job_type']=="1"){
	            $auto=true;
	        }else{
	            if($statis['integral']<$this->config['integral_partjob']*$this->config['integral_proportion']){
	                $data['error']=2;//积分不够
	                $data['msg']='积分不够';
	                echo json_encode($data);die;
	            }
	            $auto=false;
	        }
	        $nid=$this->MODEL('integral')->company_invtal($uid,$this->config['integral_partjob']*$this->config['integral_proportion'],$auto,"发布兼职");//积分操作记录
	        if ($nid){
	            if($this->config['com_partjob_status']=="1"){
	                $arr['error']='1';
	                $arr['msg']="发布成功";
	            }else{
	                $arr['error']='1';
	                $arr['msg']="发布成功，等待审核";
	            }
	        }else{
	            $arr['error']='2';
	            $arr['msg']="发布失败";
	        }
	        echo json_encode($arr);die;
	    }
	}
	function company_satic($uid){
	    $statis=$this->obj->DB_select_once("company_statis","`uid`='".$uid."'");
	    if($statis['rating']){
	        $rating=$this->obj->DB_select_once("company_rating","`id`='".$statis['rating']."'");
	    }
	    $statis['rating_type'] = $rating['type'];
	    if($statis['vip_etime']<time()){
	        /*
	         *时间会员、带有结束日期的套餐会员，如果已经过期了，设置为【过期会员或者当前会员】
	         *没有结束日期的套餐会员则根据剩余数量判断
	         *LGL
	         */
	        if($statis['vip_etime']>'1'){
	            $nums=0;
	        }else if($statis['rating_type']=='1'  &&  $statis['vip_etime']<'1'){
	            $nums=1;
	        }
	        if($nums<1){
	            if($this->config['com_vip_done']=='0'){
	                $data['job_num']=$data['down_resume']=$data['invite_resume']=$data['editjob_num']=$data['breakjob_num']=$data['part_num']=$data['editpart_num']=$data['breakpart_num']=$data['zph_num']=$data['lt_job_num']=$data['lt_editjob_num']=$data['lt_down_resume']=$data['lt_breakjob_num']='0';
	                $data['oldrating_name']=$statis['rating_name'];
	                $statis['rating_name']=$data['rating_name']="过期会员";
	                $where['uid']=$uid;
	                $this->obj->update_once("company_statis",$data,$where);
	            }elseif ($this->config['com_vip_done']=='1'){
	                $ratingM = $this->MODEL('rating');
	                $rat_value=$ratingM->rating_info($this->config['com_rating'],$uid);
	                $this->obj->DB_update_all("company_statis",$rat_value,"`uid`='".$uid."'");
	            }
	        }
	    }
	    if($statis['autotime']>=time()){
	        $statis['auto'] = 1;
	    }
	    if($statis['vip_etime']>time() || $statis['vip_etime']==0){
	        if($statis['rating_type']=="2"){
	            $addltjobnum=$addjobnum=$addpartnum=$refreshjobnum='1';
	        }else{
	            if($statis['breakjob_num']>0){
	                $refreshjobnum='1';
	            }else{
	                if($this->config['com_integral_online']=='1' || $this->config['com_integral_online']=='3'){
	                    if (intval($statis['integral']) >= intval($this->config['integral_jobefresh']*$this->config['integral_proportion'])){
	                        $refreshjobnum='2';
	                    }else{
	                        $refreshjobnum='3';
	                    }
	                }else{
	                    $refreshjobnum='0';
	                }
	            }
	            if($statis['job_num']>0){
	                $addjobnum='1';
	            }else{
	                if($this->config['com_integral_online']=='1' || $this->config['com_integral_online']=='3'){
	                    if (intval($statis['integral']) >= intval($this->config['integral_job']*$this->config['integral_proportion'])){
	                        $addjobnum='2';
	                        $addjobmsg='发布职位需要'.$this->config['integral_job']*$this->config['integral_proportion'].$this->config['integral_pricename'].',是否继续？';
	                    }else{
	                        $addjobnum='3';
	                        $addjobmsg='发布职位需要'.$this->config['integral_job']*$this->config['integral_proportion'].$this->config['integral_pricename'].',您的'.$this->config['integral_pricename'].'不足';
	                    }
	                }else{
	                    $addjobnum='0';
	                }
	            }
	            if($statis['part_num']>0){
	                $addpartnum='1';
	            }else{
	                if($this->config['com_integral_online']=='1' || $this->config['com_integral_online']=='3'){
	                    if(intval($statis['integral']) >= intval($this->config['integral_partjob']*$this->config['integral_proportion'])){
	                        $addpartnum='2';
	                        $addpartmsg='发布兼职需要'.$this->config['integral_partjob']*$this->config['integral_proportion'].$this->config['integral_pricename'].',是否继续？';
	                    }else{
	                        $addpartnum='3';
	                        $addpartmsg='发布兼职需要'.$this->config['integral_partjob']*$this->config['integral_proportion'].$this->config['integral_pricename'].',您的'.$this->config['integral_pricename'].'不足';
	                    }
	                }else{
	                    $addpartnum='0';
	                }
	            }
	        }
	    }else {
	        if($this->config['com_integral_online']=='1' || $this->config['com_integral_online']=='3'){
	            if (intval($statis['integral']) >= intval($this->config['integral_job']*$this->config['integral_proportion'])){
	                $addjobnum='2';
	            }else{
	                $addjobnum='3';
	            }
	            if(intval($statis['integral']) >= intval($this->config['integral_partjob']*$this->config['integral_proportion'])){
	                $addpartnum='2';
	            }else{
	                $addpartnum='3';
	            }
	        }else{
	            $addjobnum=$addpartnum='0';
	        }
	    }
	    $statis['refreshjobnum']=$refreshjobnum;
	    $statis['addjobnum']=$addjobnum;
	    $statis['addjobmsg']=$addjobmsg;
	    $statis['addpartnum']=$addpartnum;
	    $statis['addpartmsg']=$addpartmsg;
	    $statis['pay_format']=number_format($statis['pay'],2);
	    $statis['integral_format']=number_format($statis['integral']);
	    $statis['addjobintegral']=$this->config['integral_job']*$this->config['integral_proportion'];
	    $statis['addpartintegral']=$this->config['integral_partjob']*$this->config['integral_proportion'];
	    $statis['sxjobintegral']=$this->config['integral_partjob']*$this->config['integral_proportion'];
	    $statis['pricename']=$this->config['integral_pricename'];
	    return $statis;
	}
	/*
	 * 百度地图BD09坐标---->中国正常GCJ02坐标
	 * 腾讯地图用的也是GCJ02坐标
	 * @param double $lat 纬度
	 * @param double $lng 经度
	 * @return array();
	 */
	
	function Convert_BD09_To_GCJ02($lng,$lat){
	    $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	    $x = $lng - 0.0065;
	    $y = $lat - 0.006;
	    $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
	    $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
	    $lng = $z * cos($theta);
	    $lat = $z * sin($theta);
	    return array('lng'=>$lng,'lat'=>$lat);
	}
	/*
	 * 中国正常GCJ02坐标---->百度地图BD09坐标
	 * 腾讯地图用的也是GCJ02坐标
	 * @param double $lat 纬度
	 * @param double $lng 经度
	 */
	function Convert_GCJ02_To_BD09($lng,$lat){
	    $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	    $x = $lng;
	    $y = $lat;
	    $z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
	    $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
	    $lng = $z * cos($theta) + 0.0065;
	    $lat = $z * sin($theta) + 0.006;
	    return array('lng'=>$lng,'lat'=>$lat);
	}
}
?>